home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 272_01 / ctlbrk.doc < prev    next >
Text File  |  1986-10-12  |  2KB  |  51 lines

  1.  
  2.  
  3.         NAME
  4.                 ctlbrk -- control-break (^C) interrupt handler
  5.  
  6.         SYNOPSIS
  7.                 r = ctlbrk(func);
  8.                 int *func;
  9.                 int r;       return 0 to continue program, not zero
  10.                              to abort.
  11.  
  12.         DESCRIPTION
  13.         This function is used to install a user-written interrupt handler for
  14.         DOS int 23h, the Control-C handler.  The default handler simply exits
  15.         (ungracefully) the host program.  Using ctlbrk(), a user-written
  16.         handler may be substituted for the default.  This may be desirable if
  17.         it is absolutely necessary to prevent an untimely user-inspired exit,
  18.         or if control-C is desired to perform some function within the program.
  19.         The parameter passed is the address of the actual function.
  20.         Passing a NULL parameter re-installs the handler
  21.         which was in the interrupt table before this function altered the
  22.         vector address.  Dos re-installs the original handler upon
  23.         any program exit, so it is unnecessary to uninstall this handler
  24.         before actually exiting.
  25.  
  26.         EXAMPLE
  27.                #include <stdio.h>
  28.                #include <keys.h>
  29.                handler() {
  30.                     puts("Control-C Received!!!");
  31.                     return(0);      /* continue program */
  32.                     }
  33.  
  34.                main() {
  35.                   char ch;
  36.                   ctlbrk(&handler);
  37.                   ch = NULL;
  38.                   while(ch != ESC) {  /* loop until ESCAPE pressed */
  39.                      ch = getche();
  40.                      }
  41.                   ctlbrk(NULL);        /* uninstall our trap */
  42.                   puts("Exiting program now.  Have a nice day!");
  43.                   }
  44.  
  45.         WARNING:
  46.               Within the handler routine, keep the code simple and fast.
  47.               DO NOT use printf() or its relatives as these will destroy
  48.               the interrupt structure (for rather obscure reasons).
  49.  
  50.         This function is found in SMDLx.LIB for the Datalight Compiler
  51.